import express, { Request, Response } from 'express'
import { v4 as uuid } from 'uuid'
import {expertAddService, expertListService} from "../service/expertService";
import {parseToken} from "../utils/jwt";
import {tokenParams} from "../../global";
const router = express.Router()

router.post('/list', async (req: Request, res: Response) => {
    const token = req.headers[process.env.NODE_MANAGE_TOKEN as string] as string
    await expertListService(res, token)
})

router.post('/add', async (req: Request, res: Response) => {
    const token = req.headers[process.env.NODE_MANAGE_TOKEN as string] as string
    const userUID = (parseToken(token) as tokenParams).userUID
    const { expertName, expertID, expertWx, expertSendSample, expertAddress, expertCode } = req.body
    await expertAddService(res, [uuid(), userUID, expertName, expertID, expertWx, expertSendSample, expertAddress, expertCode])
})

export default router